From: IRIE Shinsuke Date: Wed, 13 Oct 2010 03:30:36 +0000 (-0700) Subject: * lisp/subr.el (last): Make it faster. X-Git-Tag: archive/raspbian/1%29.2+1-2+rpi1~1^2~324^2~6099 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/www.github.com/%22bookmarks:///%22http:/www.example.com/cgi/%22https:/www.github.com/%22bookmarks:/?a=commitdiff_plain;h=4902e6d53c3233542ed9ce338b5ffd1ab8f4db40;p=emacs.git * lisp/subr.el (last): Make it faster. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 855f249d3b2..335d83b1172 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,7 @@ +2010-10-13 IRIE Shinsuke (tiny change) + + * subr.el (last): Make it faster. (Bug#7174) + 2010-10-13 Rainer Orth (tiny change) * Makefile.in (compile-clean): Use `` instead of $(). (Bug#7178) diff --git a/lisp/subr.el b/lisp/subr.el index 484340895be..0ed4ae62795 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -289,14 +289,11 @@ If LIST is nil, return nil. If N is non-nil, return the Nth-to-last link of LIST. If N is bigger than the length of LIST, return LIST." (if n - (let ((m 0) (p list)) - (while (consp p) - (setq m (1+ m) p (cdr p))) - (if (<= n 0) p - (if (< n m) (nthcdr (- m n) list) list))) - (while (consp (cdr list)) - (setq list (cdr list))) - list)) + (and (> n 0) + (let ((m (length list))) + (if (< n m) (nthcdr (- m n) list) list))) + (and list + (nthcdr (1- (length list)) list)))) (defun butlast (list &optional n) "Return a copy of LIST with the last N elements removed."